Trò chơi đua xe động vật trong UNITY Engine
114.746 lượt xem;
- XmlUtils.cs
- Utils /
- Editor /
- Spriter2Unity /
- ThirdParty /
- Assets /
- project /
1 /*
2 Copyright (c) 2014 Andrew Jones, Dario Seyb
3 Based on 'Spriter2Unity' python code by Malhavok
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23
24 using System.Xml;
25 using UnityEngine;
26
27 namespace Assets.ThirdParty.Spriter2Unity.Editor.Spriter
28 {
29 public static class XmlUtils
30 {
31 public static bool TryGetString(this XmlNode node, string key, out string value)
32 {
33 value = default(string);
34 var attr = node.Attributes[key];
35 bool parsed = false;
36 if (attr != null)
37 {
38 parsed = true;
39 value = attr.Value;
40 }
41
42 return parsed;
43 }
44
45 public static bool TryGetInt(this XmlNode node, string key, out int value)
46 {
47 value = default(int);
48 var attr = node.Attributes[key];
49 bool parsed = false;
50 if (attr != null)
51 {
52 parsed = int.TryParse(attr.Value, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out value);
53 }
54
55 return parsed;
56 }
57
58 public static bool TryGetFloat(this XmlNode node, string key, out float value)
59 {
60 value = default(float);
61 var attr = node.Attributes[key];
62 bool parsed = false;
63 if (attr != null)
64 {
65 parsed = float.TryParse(attr.Value, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out value);
66 }
67
68 return parsed;
69 }
70
71 public static bool TryGetVector2(this XmlNode node, out Vector2 value)
72 {
73 value = default(Vector2);
74 float tmp;
75 bool parsed = true;
76 if (TryGetFloat(node, "x", out tmp)) value.x = tmp;
77 else parsed = false;
78 if (TryGetFloat(node, "y", out tmp)) value.y = tmp;
79 else parsed = false;
80
81 return parsed;
82 }
83
84 public static bool TryGetVector3(this XmlNode node, out Vector3 value)
85 {
86 value = default(Vector3);
87 float tmp;
88 bool parsed = true;
89 if (TryGetFloat(node, "x", out tmp)) value.x = tmp;
90 else parsed = false;
91 if (TryGetFloat(node, "y", out tmp)) value.y = tmp;
92 else parsed = false;
93 if (TryGetFloat(node, "z", out tmp)) value.z = tmp;
94 else parsed = false;
95
96 return parsed;
97 }
98
99 public static string GetString(this XmlNode node, string key, string defaultVal)
100 {
101 string value = defaultVal;
102 var attr = node.Attributes[key];
103 if (attr != null)
104 {
105 value = attr.Value;
106 }
107 return value;
108 }
109
110 public static int GetInt(this XmlNode node, string key, int defaultVal)
111 {
112 int value = defaultVal;
113 int tmp;
114 if (TryGetInt(node, key, out tmp)) value = tmp;
115
116 return value;
117 }
118
119 public static float GetFloat(this XmlNode node, string key, float defaultVal)
120 {
121 var value = defaultVal;
122 float tmp;
123 if (TryGetFloat(node, key, out tmp)) value = tmp;
124
125 return value;
126 }
127
128 public static Vector2 GetVector2(this XmlNode node, Vector2 defaultVal)
129 {
130 var value = defaultVal;
131 float tmp;
132 if (TryGetFloat(node, "x", out tmp)) value.x = tmp;
133 if (TryGetFloat(node, "y", out tmp)) value.y = tmp;
134
135 return value;
136 }
137
138 public static Vector3 GetVector3(this XmlNode node)
139 {
140 var value = default(Vector3);
141 float tmp;
142 if (TryGetFloat(node, "x", out tmp)) value.x = tmp;
143 if (TryGetFloat(node, "y", out tmp)) value.y = tmp;
144 if (TryGetFloat(node, "z", out tmp)) value.z = tmp;
145
146 return value;
147 }
148 }
149 }
2 Copyright (c) 2014 Andrew Jones, Dario Seyb
3 Based on 'Spriter2Unity' python code by Malhavok
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23
24 using System.Xml;
25 using UnityEngine;
26
27 namespace Assets.ThirdParty.Spriter2Unity.Editor.Spriter
28 {
29 public static class XmlUtils
30 {
31 public static bool TryGetString(this XmlNode node, string key, out string value)
32 {
33 value = default(string);
34 var attr = node.Attributes[key];
35 bool parsed = false;
36 if (attr != null)
37 {
38 parsed = true;
39 value = attr.Value;
40 }
41
42 return parsed;
43 }
44
45 public static bool TryGetInt(this XmlNode node, string key, out int value)
46 {
47 value = default(int);
48 var attr = node.Attributes[key];
49 bool parsed = false;
50 if (attr != null)
51 {
52 parsed = int.TryParse(attr.Value, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out value);
53 }
54
55 return parsed;
56 }
57
58 public static bool TryGetFloat(this XmlNode node, string key, out float value)
59 {
60 value = default(float);
61 var attr = node.Attributes[key];
62 bool parsed = false;
63 if (attr != null)
64 {
65 parsed = float.TryParse(attr.Value, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out value);
66 }
67
68 return parsed;
69 }
70
71 public static bool TryGetVector2(this XmlNode node, out Vector2 value)
72 {
73 value = default(Vector2);
74 float tmp;
75 bool parsed = true;
76 if (TryGetFloat(node, "x", out tmp)) value.x = tmp;
77 else parsed = false;
78 if (TryGetFloat(node, "y", out tmp)) value.y = tmp;
79 else parsed = false;
80
81 return parsed;
82 }
83
84 public static bool TryGetVector3(this XmlNode node, out Vector3 value)
85 {
86 value = default(Vector3);
87 float tmp;
88 bool parsed = true;
89 if (TryGetFloat(node, "x", out tmp)) value.x = tmp;
90 else parsed = false;
91 if (TryGetFloat(node, "y", out tmp)) value.y = tmp;
92 else parsed = false;
93 if (TryGetFloat(node, "z", out tmp)) value.z = tmp;
94 else parsed = false;
95
96 return parsed;
97 }
98
99 public static string GetString(this XmlNode node, string key, string defaultVal)
100 {
101 string value = defaultVal;
102 var attr = node.Attributes[key];
103 if (attr != null)
104 {
105 value = attr.Value;
106 }
107 return value;
108 }
109
110 public static int GetInt(this XmlNode node, string key, int defaultVal)
111 {
112 int value = defaultVal;
113 int tmp;
114 if (TryGetInt(node, key, out tmp)) value = tmp;
115
116 return value;
117 }
118
119 public static float GetFloat(this XmlNode node, string key, float defaultVal)
120 {
121 var value = defaultVal;
122 float tmp;
123 if (TryGetFloat(node, key, out tmp)) value = tmp;
124
125 return value;
126 }
127
128 public static Vector2 GetVector2(this XmlNode node, Vector2 defaultVal)
129 {
130 var value = defaultVal;
131 float tmp;
132 if (TryGetFloat(node, "x", out tmp)) value.x = tmp;
133 if (TryGetFloat(node, "y", out tmp)) value.y = tmp;
134
135 return value;
136 }
137
138 public static Vector3 GetVector3(this XmlNode node)
139 {
140 var value = default(Vector3);
141 float tmp;
142 if (TryGetFloat(node, "x", out tmp)) value.x = tmp;
143 if (TryGetFloat(node, "y", out tmp)) value.y = tmp;
144 if (TryGetFloat(node, "z", out tmp)) value.z = tmp;
145
146 return value;
147 }
148 }
149 }